﻿using System;
namespace wuo
{
    using wuo.convert;
    using wuo.helpers;

    public class WuoConvert
    {
        public static WuoConvert C001 = new WuoConvert(new Convert_C001());

        public static object? DeserializeObject(string msg, Type type)
        {
            return C001.Deserialize(msg, type);
        }
        public static T? DeserializeObject<T>(string msg)
        {
            return C001.Deserialize<T>(msg);
        }
        public static string SerializeObject(object obj)
        {
            return C001.Serialize(obj);
        }
        internal IWuoConvert cv { get; set; }
        internal WuoConvert(IWuoConvert wuoConvert)
        {
            this.cv = wuoConvert;
        }
        public object? Deserialize(string msg, Type type)
        {
            var twuo = helper.resolve_wuo(msg);
            if (twuo == _typ.typwuo.C001) return new Convert_C001().DeserializeObject(msg, type);
            msg = msg.Substring(2);
            return null;
        }
        public T? Deserialize<T>(string msg)
        {
            return (T?)DeserializeObject(msg, typeof(T));
        }
        public string Serialize(object obj)
        {
            return cv.SerializeObject(obj);
        }
    }
}
